﻿<UserControl x:Class="OPMLtools.Infrastructure.Views.OpmlView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vm="clr-namespace:OPMLtools.Infrastructure.ViewModels"
             xmlns:conv="clr-namespace:OPMLtools.Common.Converters"
             xmlns:exTollkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <vm:OpmlViewModel x:Key="vmOpmlViewModel"/>
        <conv:OverrideCursorConvertor x:Key="convOverrideCursorConvertor"/>
    </UserControl.Resources>
    <exTollkit:BusyIndicator DataContext="{Binding Source={StaticResource vmOpmlViewModel}}" 
                                             IsBusy="{Binding IsBusy }"
                                             BusyContent="Please wait..." >
        <Grid >
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="auto"/>
            </Grid.RowDefinitions>
            <GroupBox Header="OPML" Margin="5,5,5,1" Grid.Row="0">
                <Grid Margin="3">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="auto" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="auto" />
                        <RowDefinition Height="auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="OPML Path:" Grid.Column="0" Grid.Row="0" Margin="3" VerticalAlignment="Center"/>
                    <TextBox IsReadOnly="True" Grid.Column="1" Grid.Row="0" VerticalAlignment="Center" Margin="3"  Text="{Binding FilePath,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}" x:Name="txtPath"/>
                    <Button Grid.Column="2" Grid.Row="0" VerticalAlignment="Center" Margin="3" Content="..." Width="30" Height="25" x:Name="btnGetPath" Click="btnGetPath_Click" />
                    <!--<Button Grid.Column="0" Grid.Row="1" Margin="3" Content="Get OPML" Height="25" Command="{Binding GetOpmlCommand}" Cursor="{Binding IsBusy,Converter={StaticResource convOverrideCursorConvertor}}"/>-->
                    <Button Grid.Column="0" Grid.Row="1" Margin="3"  Height="25" Command="{Binding GetOpmlCommand}" >
                        <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="1" Orientation="Horizontal">
                            <Image Source="/OPMLtools;Component/Images/getOpml.png" Height="16" Width="16" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="1" />
                            <TextBlock Text="Get OPML"  VerticalAlignment="Center" HorizontalAlignment="Center" Margin="1" />
                        </StackPanel>
                    </Button>

                </Grid>
            </GroupBox>
            <GroupBox Header="OPML list" Margin="5,1,5,5" Grid.Row="1">
                <Grid Margin="3">

                    <ListView Margin="3" VirtualizingStackPanel.IsVirtualizing="True" VirtualizingStackPanel.VirtualizationMode="Recycling" ItemsSource="{Binding Opmls}" Grid.RowSpan="2">
                        <ListView.View>
                            <GridView>

                                <GridViewColumn Header="Site URL" Width="300">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding HtmlUrl}" Foreground="Cyan" HorizontalAlignment="Center"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                                <GridViewColumn Header="Count" Width="50">
                                    <GridViewColumn.CellTemplate>
                                        <DataTemplate>
                                            <TextBlock Text="{Binding Count}" HorizontalAlignment="Center"/>
                                        </DataTemplate>
                                    </GridViewColumn.CellTemplate>
                                </GridViewColumn>

                            </GridView>
                        </ListView.View>
                    </ListView>

                </Grid>
            </GroupBox>
            <Button Grid.Row="2"  Margin="0,5,5,5" Height="25" HorizontalAlignment="Right" Padding="5,0,5,0" VerticalAlignment="Center" Command="{Binding RemoveDuplicateCommand}" ToolTip="Remove duplicate nodes and save new OPML file ">
                <StackPanel VerticalAlignment="Center" HorizontalAlignment="Center" Margin="1" Orientation="Horizontal">
                    <Image Source="/OPMLtools;Component/Images/removeDuplicate.png" Height="16" Width="16" VerticalAlignment="Center" HorizontalAlignment="Center" Margin="1" />
                    <TextBlock Text="Remove Duplicate"  VerticalAlignment="Center" HorizontalAlignment="Center" Margin="1" />
                </StackPanel>
            </Button>

        </Grid>
    </exTollkit:BusyIndicator>
</UserControl>
